package sxe.core.string;

import snobject.snBoolean;
import snobject.snDouble;
import snobject.snInteger;
import snobject.snObject;
import snobject.snObjectArgList;
import snobject.snString;
import step.EvaluationFailure;
import step.FunctionWrapper;

public class castToString extends FunctionWrapper {

	@Override
	public snObject Call(snObjectArgList argv) throws EvaluationFailure,
			ClassCastException, ArrayIndexOutOfBoundsException {
		
		if(argv.length()!=1)
			throw new ArrayIndexOutOfBoundsException();
		
		snObject sno = argv.popObject();
		if(sno instanceof snString)
			return sno;
		if(sno instanceof snInteger)
			return new snString(((snInteger)sno).getInteger().toString());
		if(sno instanceof snBoolean)
			return new snString( new String(((snBoolean)sno).getWeb()) );
		if(sno instanceof snDouble)
			return new snString(((snDouble)sno).getDouble().toString());

		throw new ClassCastException();
		
	}

}
